﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
#if NETFX_CORE
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
#else
using System.Windows.Media;
using System.Windows.Shapes;
#endif
using ArchiSimple.Windows.Model;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;

namespace ArchiSimple.Windows.ViewModel.PlanObjects
{
    public abstract class PlanObjectViewModel : ViewModelBase
    {
        public class Rectangle : ViewModelBase
        {
            public Rectangle()
            {
                this.X = 0;
                this.Y = 0;
                this.Width = 0;
                this.Height = 0;
            }

            public double X
            {
                get { return this.Get<double>("X"); }
                set { this.Set<double>("X", value); }
            }

            public double Y
            {
                get { return this.Get<double>("Y"); }
                set { this.Set<double>("Y", value); }
            }
            
            public double Width
            {
                get { return this.Get<double>("Width"); }
                set { this.Set<double>("Width", value); }
            }
            
            public double Height
            {
                get { return this.Get<double>("Height"); }
                set { this.Set<double>("Height", value); }
            }
        }

        public PlanObjectViewModel()
        {
            this.DeleteCommand = new RelayCommand(() =>
            {
                this.Delete();
            });
        }

        public Rectangle Zone
        {
            get { return this.Get<Rectangle>("Zone"); }
            set { this.Set<Rectangle>("Zone", value); }
        }

        public abstract PlanObject PlanObject { get; }

        public abstract PathGeometry SelectedGeometry { get; }

        public static PlanObjectViewModel Create(PlanViewModel plan, PlanObject o)
        {
            var config = new { plan = plan, model = o };

            switch (o.PlanObjectType)
            {
                case PlanObjectType.Room:
                    return Locator.Locate<RoomViewModel>(config);
                case PlanObjectType.Point:
                    return Locator.Locate<PointViewModel>(config);
                case PlanObjectType.Wall:
                    return Locator.Locate<WallViewModel>(config);
                default:
                    throw new NotImplementedException();
            }
        }

        public ICommand DeleteCommand { get; set; }

        public abstract void Delete();
    }
}
